package com.myapp.util;

import android.util.DisplayMetrics;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnTouchListener;
import android.widget.LinearLayout;

import com.myapp.R;


public class ScreenManager {
	
	public static int getWidth(float ratio,DisplayMetrics metrics){
		return (int) (metrics.widthPixels * ratio);
	}
	
	public static int getHeight(float ratio,DisplayMetrics metrics){
		return (int) (metrics.heightPixels * ratio);
	}

	public static int getLayoutWidth(float ratio,int width){
		return (int) (ratio * width);
	}

	public static int getLayoutHeight(float ratio,int height){
		return (int) (ratio * height);
	}
	
	public static void setMyLayoutParam(View v,int width,int height){
		v.setLayoutParams(new LinearLayout.LayoutParams(width, height));
	}
	
	public static void setNormalPress(View v){
		v.setOnTouchListener(new OnTouchListener() {
			@Override
			public boolean onTouch(View v, MotionEvent event) {
				if(event.getAction() == MotionEvent.ACTION_DOWN){
					v.setBackgroundResource(R.color.mask);
				}else if(event.getAction() == MotionEvent.ACTION_UP || event.getAction() == MotionEvent.ACTION_CANCEL){
					v.setBackgroundResource(R.color.transparent);
				}
				return true;
			}
		});
	}
	
}
